package example.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * TODO
 *
 * @author zgq
 * @date 2020/10/22 15:12
 */
public class MyUserDetail implements UserDetails {
    //    private UserDetails userDetails;
    private String token;

    private SysUser sysUser;

    @JsonIgnore
    private String password;
    private String username;
    private boolean enable;


//    public MyUserDetail(SysUser sysUser){
//        this.username = sysUser.getAccount();
//        this.password = sysUser.getPwd();
//    }

    public MyUserDetail(SysUser sysUser) {
        this.sysUser = sysUser;
        this.username = sysUser.getAccount();
        this.password = sysUser.getPwd();
        this.enable = true;
    }

    public SysUser getSysUser() {
        return sysUser;
    }

    public void setSysUser(SysUser sysUser) {
        this.sysUser = sysUser;
    }


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return Lists.newArrayList(new SimpleGrantedAuthority("test"));
    }

    @Override
    public String getPassword() {
        return sysUser.getPwd();
    }

    @Override
    public String getUsername() {
        return sysUser.getAccount();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
